package com.gewu.bookeeping.View.ItemFragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;

import com.gewu.bookeeping.MyDb.bean.ALIBeanIn;
import com.gewu.bookeeping.MyDb.bean.ALiBeanOut;
import com.gewu.bookeeping.MyDb.bean.MesBeanIn;
import com.gewu.bookeeping.MyDb.bean.WeChtBeanIn;
import com.gewu.bookeeping.MyDb.bean.WeChtBeanOut;
import com.gewu.bookeeping.MyDb.dao.ALiDaoInPerson;
import com.gewu.bookeeping.MyDb.dao.ALiDaoOutPerson;
import com.gewu.bookeeping.MyDb.dao.MesInPerson;
import com.gewu.bookeeping.MyDb.dao.MesOutPerson;
import com.gewu.bookeeping.MyDb.dao.WeChtDaoInPerson;
import com.gewu.bookeeping.MyDb.dao.WeChtDaoOutPerson;
import com.gewu.bookeeping.R;
import com.gewu.bookeeping.Utils.MyNotiListion;
import com.gewu.bookeeping.View.adapter.twoItemAdapter;

import java.util.ArrayList;
import java.util.List;

public class twoItem1Fragment extends Fragment {

    List<String> time = new ArrayList<>();
    ExpandableListView expandableListView;
    List<List<MesBeanIn>> listList = new ArrayList<>();
    List<MesBeanIn> objectList1 = new ArrayList<>();
    List<MesBeanIn> objectList2 = new ArrayList<>();
    List<MesBeanIn> objectList3 = new ArrayList<>();
    List<MesBeanIn> objectList4 = new ArrayList<>();
    List<MesBeanIn> objectList5 = new ArrayList<>();
    List<MesBeanIn> objectList6 = new ArrayList<>();
    List<MesBeanIn> objectList7 = new ArrayList<>();
    List<MesBeanIn> objectList8 = new ArrayList<>();
    List<MesBeanIn> objectList9 = new ArrayList<>();
    List<MesBeanIn> objectList10 = new ArrayList<>();
    List<MesBeanIn> objectList11 = new ArrayList<>();
    List<MesBeanIn> objectList12 = new ArrayList<>();
    private twoItemAdapter twoItemAdapter;


    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = LayoutInflater.from(container.getContext()).inflate(R.layout.activity_two_item1_fragment, container, false);
        initView(inflate);
        getshuJU();
        setAdapter();
        return inflate;
    }

    private void setAdapter() {
        twoItemAdapter = new twoItemAdapter(listList, time);
        expandableListView.setAdapter(twoItemAdapter);
    }

    private void getshuJU() {
        MesInPerson mesInPerson6 = new MesInPerson(getContext());
        List<MesBeanIn> quer5 = mesInPerson6.quer();
        for (int i = 0; i < quer5.size(); i++) {
            mesInPerson6.delect(quer5.get(i).getId());
        }

        WeChtDaoOutPerson weChtDaoOutPerson = new WeChtDaoOutPerson(getContext());
        List<WeChtBeanOut> quer = weChtDaoOutPerson.quer();
        if (quer != null) {
            for (int i = 0; i < quer.size(); i++) {
                MesInPerson mesInPerson = new MesInPerson(getContext());
                MesBeanIn mesBeanIn = new MesBeanIn();
                mesBeanIn.setText(quer.get(i).getText());
                mesBeanIn.setTime(quer.get(i).getTime());
                mesBeanIn.setType(quer.get(i).getType());
                mesBeanIn.setMoney(quer.get(i).getMoney());
                mesInPerson.add(mesBeanIn);
            }
        }

        WeChtDaoInPerson weChtDaoInPerson = new WeChtDaoInPerson(getContext());
        List<WeChtBeanIn> quer1 = weChtDaoInPerson.quer();
        if (quer1 != null) {
            for (int i = 0; i < quer1.size(); i++) {
                MesInPerson mesInPerson = new MesInPerson(getContext());
                MesBeanIn mesBeanIn = new MesBeanIn();
                mesBeanIn.setText(quer1.get(i).getText());
                mesBeanIn.setTime(quer1.get(i).getTime());
                mesBeanIn.setType(quer1.get(i).getType());
                mesBeanIn.setMoney(quer1.get(i).getMoney());
                mesInPerson.add(mesBeanIn);
            }
        }

        ALiDaoOutPerson aLiDaoOutPerson = new ALiDaoOutPerson(getContext());
        List<ALiBeanOut> quer2 = aLiDaoOutPerson.quer();
        if (quer2 != null) {
            for (int i = 0; i < quer2.size(); i++) {
                MesInPerson mesInPerson = new MesInPerson(getContext());
                MesBeanIn mesBeanIn = new MesBeanIn();
                mesBeanIn.setText(quer2.get(i).getText());
                mesBeanIn.setTime(quer2.get(i).getTime());
                mesBeanIn.setType(quer2.get(i).getType());
                mesBeanIn.setMoney(quer2.get(i).getMoney());
                mesInPerson.add(mesBeanIn);
            }
        }

        ALiDaoInPerson aLiDaoInPerson = new ALiDaoInPerson(getContext());
        List<ALIBeanIn> quer3 = aLiDaoInPerson.quer();
        if (quer3 != null) {
            for (int i = 0; i < quer3.size(); i++) {
                MesInPerson mesInPerson = new MesInPerson(getContext());
                MesBeanIn mesBeanIn = new MesBeanIn();
                mesBeanIn.setText(quer3.get(i).getText());
                mesBeanIn.setTime(quer3.get(i).getTime());
                mesBeanIn.setType(quer3.get(i).getType());
                mesBeanIn.setMoney(quer3.get(i).getMoney());
                mesInPerson.add(mesBeanIn);
            }
        }

        MesInPerson mesInPerson = new MesInPerson(getContext());
        List<MesBeanIn> quer4 = mesInPerson.quer();

        if (quer4 != null) {
            for (int i = 0; i < quer4.size(); i++) {
                if (quer4.get(i).getTime().contains("2021-01")) {
                    isHave("2021-01");
                    if (!objectList1.contains(quer4.get(i))) {
                        objectList1.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-02")) {
                    isHave("2021-02");
                    if (!objectList2.contains(quer4.get(i))) {
                        objectList2.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-03")) {
                    isHave("2021-03");
                    if (!objectList3.contains(quer4.get(i))) {
                        objectList3.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-04")) {
                    isHave("2021-04");
                    if (!objectList4.contains(quer4.get(i))) {
                        objectList4.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-05")) {
                    isHave("2021-05");
                    if (!objectList5.contains(quer4.get(i))) {
                        objectList5.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-06")) {
                    isHave("2021-06");
                    if (!objectList6.contains(quer4.get(i))) {
                        objectList6.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-07")) {
                    isHave("2021-07");
                    if (!objectList7.contains(quer4.get(i))) {
                        objectList7.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-08")) {
                    isHave("2021-08");
                    if (!objectList8.contains(quer4.get(i))) {
                        objectList8.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-09")) {
                    isHave("2021-09");
                    if (!objectList9.contains(quer4.get(i))) {
                        objectList9.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-10")) {
                    isHave("2021-10");
                    if (!objectList10.contains(quer4.get(i))) {
                        objectList10.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-11")) {
                    isHave("2021-11");
                    if (!objectList11.contains(quer4.get(i))) {
                        objectList11.add(quer4.get(i));
                    }
                } else if (quer4.get(i).getTime().contains("2021-12")) {
                    isHave("2021-12");
                    if (!objectList12.contains(quer4.get(i))) {
                        objectList12.add(quer4.get(i));
                    }
                }
            }
        }


        for (int i = 0; i < time.size(); i++) {
            if (time.get(i).equals("2021-01")) {
                if (listList.contains(objectList1)) {
                    return;
                }
                listList.add(objectList1);
            } else if (time.get(i).equals("2021-02")) {
                if (listList.contains(objectList2)) {
                    return;
                }
                listList.add(objectList2);
            } else if (time.get(i).equals("2021-03")) {
                if (listList.contains(objectList3)) {
                    return;
                }
                listList.add(objectList3);
            } else if (time.get(i).equals("2021-04")) {
                if (listList.contains(objectList4)) {
                    return;
                }
                listList.add(objectList4);
            } else if (time.get(i).equals("2021-05")) {
                if (listList.contains(objectList5)) {
                    return;
                }
                listList.add(objectList5);
            } else if (time.get(i).equals("2021-06")) {
                if (listList.contains(objectList6)) {
                    return;
                }
                listList.add(objectList6);
            } else if (time.get(i).equals("2021-07")) {
                if (listList.contains(objectList7)) {
                    return;
                }
                listList.add(objectList7);
            } else if (time.get(i).equals("2021-08")) {
                if (listList.contains(objectList8)) {
                    return;
                }
                listList.add(objectList8);
            } else if (time.get(i).equals("2021-09")) {
                if (listList.contains(objectList9)) {
                    return;
                }
                listList.add(objectList9);
            } else if (time.get(i).equals("2021-10")) {
                if (listList.contains(objectList10)) {
                    return;
                }
                listList.add(objectList10);
            } else if (time.get(i).equals("2021-11")) {
                if (listList.contains(objectList11)) {
                    return;
                }
                listList.add(objectList11);
            } else if (time.get(i).equals("2021-12")) {
                if (listList.contains(objectList12)) {
                    return;
                }
                listList.add(objectList12);
            }
        }
    }

    public void isHave(String s) {
        if (time.contains(s)) {
            return;
        }
        time.add(s);
    }


    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
    private void initView(View inflate) {
        expandableListView = inflate.findViewById(R.id.etListview);
    }

}